package com.ztc.ZtcRefundRecord.service;

import com.aqgj.util.JsonWrapper;
import com.ztc.ZtcRefundRecord.bean.ZtcRefundRecord;
import com.ztc.ZtcRefundRecord.dao.ZtcRefundRecordDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service("ZtcRefundRecord")
public class ZtcRefundRecordManager {

    @Autowired
    ZtcRefundRecordDao ztcRefundRecordDao;

    /**
     * 获取退款列表
     * @param pageNo  页码
     * @param pageSize 条数
     * @param type  当前公司类型
     * @param cid   当前公司ID
     * @return  列表集合
     */
    public List getRecordList(int pageNo, int pageSize, Integer type, String cid) {
        List list = ztcRefundRecordDao.getRecordList(pageNo, pageSize, type, cid);
        if (list.size() == 0) {
            return null;
        }
        return ztcRefundRecordDao.getKeyList(list, "id", "name", "type", "orderNumber", "orderBalance", "money", "addTime");
    }

    /**
     * 获取退款总数
     *
     * @return 退款总条数
     */
    public Integer getSqlSumQuery(Integer type, String cid) {
        return ztcRefundRecordDao.getSqlSumQuery(type, cid);
    }

    public ZtcRefundRecord get(String zid) {
        return ztcRefundRecordDao.get(zid);
    }

    /**
     * 退款记录详情
     * @param rid  退款ID
     * @param type 订单类型（1直通车订单，2携程订单）
     * @return MAP
     */
    public HashMap<String, Object> getRecordInfo(String rid, Integer type) {
        Object[] objects=  ztcRefundRecordDao.getRecordInfo(rid,type);
        String[] result={"name","refundType","orderNumber","orderBalance","payBalance","payType","orderType","orderTime","refundMoney","refundAddTime","carType","departureDate","personnel"};
        HashMap<String,Object> map=new HashMap<>();
        if(objects!=null){
            for (int i=0;i<result.length;i++) {
                map.put(result[i],objects[i]);
            }
        }
        return JsonWrapper.successWrapper(map);
    }
}
